package org.example.curriculum_design_6_16.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.curriculum_design_6_16.entity.pojo.AttendanceAbsence;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* @author 郑凯
* @description 针对表【attendance_absence】的数据库操作Mapper
* @createDate 2025-06-18 19:00:52
* @Entity org.example.curriculum_design_6_16.entity.pojo.AttendanceAbsence
*/
@Mapper
public interface AttendanceAbsenceMapper extends BaseMapper<AttendanceAbsence> {
    @Insert("INSERT INTO attendance_absence (student_id, absence_date, activity_name, " +
            "activity_type, academic_year, is_approved) " +
            "VALUES (#{studentId}, #{absenceDate}, #{activityName}, " +
            "#{activityType}, #{academicYear}, #{isApproved})")
    int insertAbsenceRecord(
            @Param("studentId") String studentId,
            @Param("absenceDate") java.sql.Date absenceDate,
            @Param("activityName") String activityName,
            @Param("activityType") String activityType,
            @Param("academicYear") String academicYear,
            @Param("isApproved") Boolean isApproved);

    @Select("SELECT COUNT(*) FROM attendance_absence " +
            "WHERE student_id = #{studentId} " +
            "AND academic_year = #{academicYear} " +
            "AND is_approved = 0")
    int countUnapprovedAbsences(
            @Param("studentId") String studentId,
            @Param("academicYear") String academicYear);
}




